
//start cleaning file here
use "$raw/all_s4_mock_noPII.dta", clear


replace ENG=6 if ENG==46
local exams ENG	MTC	
foreach x of local exams {
replace `x'=18 if `x'==1
replace `x'=17 if `x'==2
replace `x'=16 if `x'==3
replace `x'=15 if `x'==4
replace `x'=14 if `x'==5
replace `x'=13 if `x'==6
replace `x'=12 if `x'==7
replace `x'=11 if `x'==8
replace `x'=10 if `x'==9
replace `x'=`x'-10
}
local exams ENG	MTC	AGG
replace AGG=75-AGG // so higher better
foreach x of local exams {
egen mean_`x' = mean(`x') 
egen sd_`x' = sd(`x') 
egen mean_`x'2=max(mean_`x')
egen sd_`x'2=max(sd_`x')
gen std_`x' = (`x' - mean_`x'2) / sd_`x'2
}


ren std_ENG std_ENG_mock
ren std_MTC std_MTC_mock
ren std_AGG std_AGG_mock
ren AGG AGG_mock
ren MTC MTC_mock
ren ENG ENG_mock
la var std_AGG_mock "standardised raw total score"


keep *_mock id SCHOOL 

save "$cleaned/all_s4_mock_cleaned.dta", replace
